package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturnOpration implements IOperation{
    @Override
    public void work(BookList bookList) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要查找的书名：");
        String name = sc.nextLine();
        for (int i = 0; i < bookList.getSize(); i++) {
            Book book = bookList.getBook(i);
            if(name.equals(book.getName()) == true){
                if(book.isBorrow() == true){
                    book.setBorrow(false);
                    System.out.println("成功归还");
                }else {
                    System.out.println("抱歉，书未借出");
                }
                return;
            }
        }
        System.out.println("抱歉，查无此书");
    }
}
